﻿using Microsoft.AspNet.SignalR;
using Ninject;
using ZSoft.PushServices.Net.Services;
using ZSoft.PushServices.Net.Services.NotificationQueue;
using ZSoft.PushServices.Net.Transport;
using ZSoft.PushServices.Server.Infra.DI;
using ZSoft.PushServices.Server.Infra.Events;

namespace ZSoft.PushServices.Server.Infra.App_Start
{
    public class SetupSignalRResolvers : IEventHandler
    {
        public AppEventType EventType
        {
            get
            {
                return AppEventType.Application_Start;
            }
        }

        public void Execute()
        {
            StandardKernel kernel = new StandardKernel();
            NinjectSignalRDependencyResolver resolver = new NinjectSignalRDependencyResolver(kernel);
            RegisterTypes(kernel);
            GlobalHost.DependencyResolver = new NinjectSignalRDependencyResolver(kernel);
        }
        
        private void RegisterTypes(StandardKernel kernel)
        {

            kernel
                .Bind<IConnectionManager>()
                    .To<InMemoryConnectionManager>()
                        .InSingletonScope();
            kernel
                .Bind<INotificationService>()
                    .To<HubNotificationService>();
            kernel
                .Bind<INotificationQueueProvider>()
                    .To<DefaultQueueProvider>()
                        .InSingletonScope();
        }
    }
}